<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //$this->getWeatherCity();
        $this->getWeather();
    }

    public function getWeatherCity()
    {
        $client = new \GuzzleHttp\Client();
        $response = $client->request(
            'GET',
            'http://jisutqybmf.market.alicloudapi.com/weather/city',
            [
                'headers' => [
                    'Authorization' => 'APPCODE 1febb8104bed449584e6b90f4d2f034c',
                ]
            ]
        );
        echo $response->getStatusCode();
        $contents = $response->getBody()->getContents();
        file_put_contents("./city.json", $contents);
    }

    public function getWeather()
    {
        $client = new \GuzzleHttp\Client();
        $response = $client->request(
            'GET',
            'http://jisutqybmf.market.alicloudapi.com/weather/query',
            [
                'headers' => [
                    'Authorization' => 'APPCODE 1febb8104bed449584e6b90f4d2f034c',
                ],
                'query' => [
                    'citycode' => 101290201,
                ]
            ]
        );
        echo $response->getStatusCode();
        $contents = $response->getBody()->getContents();
        file_put_contents("./weather.json", $contents);
    }
}
